package saucaca.fragment;

import lemon.kenhnhacvn.BaseEngine;
import lemon.kenhnhacvn.R;
import saucaca.JSON.WServiceLib;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class InfoDetailFragment extends Fragment {
	String guideID;
	TextView txtContent;
	private View mView_EmptyLoading = null;
	private ProgressBar progressBar;
	ImageView imgEmpty, imgError;
	TextView txtStatus;
	String empty = "No info!";

	public InfoDetailFragment(String guideID) {
		this.guideID = guideID;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View android = inflater.inflate(R.layout.about, container, false);
		findviewByID(android);
		if (guideID != null) {
			new getGuide().execute("");
		} else {
			progressBar.setVisibility(View.GONE);
			txtStatus.setText(empty);
			imgEmpty.setVisibility(View.VISIBLE);
		}
		return android;
	}

	void findviewByID(View view) {
		txtContent = (TextView) view.findViewById(R.id.about_textInfo);
		mView_EmptyLoading = view.findViewById(R.id.empty_loading);
		progressBar = (ProgressBar) mView_EmptyLoading.findViewById(R.id.empty_loading_progress);
		imgEmpty = (ImageView) mView_EmptyLoading.findViewById(R.id.empty_loading_NoItem);
		imgError = (ImageView) mView_EmptyLoading.findViewById(R.id.empty_loading_Error);
		txtStatus = (TextView) mView_EmptyLoading.findViewById(R.id.empty_loading_text);
	}

	class getGuide extends AsyncTask<String, String, String> {

		@Override
		protected String doInBackground(String... params) {
			String str = WServiceLib.guide(guideID);
			BaseEngine.showLogformLongString(str);
			return str;
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			if (result != null && result.equals("")) {
				txtContent.setText(result);
			} else {
				imgEmpty.setVisibility(View.VISIBLE);
				txtStatus.setText(empty);
			}
			progressBar.setVisibility(View.GONE);
		}

	}

}
